home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / m68k / fbug68k.arc / BF.C < prev    next >
C/C++ Source or Header  |  1989-08-17  |  5KB  |  153 lines

  1. #include"userdef.h"
  2.  
  3. /* **************************************************** */
  4. /*
  5. bf [<size>] <range> <data>
  6. Block fill -> This command fills an area of memory
  7. described by <range> with what ever is in the <data> field.
  8.  
  9. The objective of this command is to provide a simple way to
  10. set an area of memory to a value and check that the memory
  11. was correctly set. 
  12.  
  13. If the size of the data and the size of the area to be filled
  14. are not equal, the command will leave the last partial word or 
  15. half word, or longword unchanged. This is indicated by the bf
  16. command when it reports where it started, where it stopped and 
  17. what data it used. If the data is larger than the size chosen,
  18. then the begining of the data will be truncated to fit.
  19.  
  20. The subroutine first checks to see if the number of arguments on
  21. the command line is correct. Since <size> is optional, the allowable
  22. number of arguments on the command line may be 3 or 4.
  23. if the number of arguments on the command line are not correct,
  24. then drop down to the end of the program and print an error.
  25.  
  26. If the number of arguments on the command line are correct, then
  27. we parse the command line.
  28. If at any time an error occurs in getting an argument, then we
  29. return to the main loop without changing any memory space.
  30. First we get the <size> from the command line (or have it set to
  31. the default). 
  32. Second we get the <range> from the command line. This involves getting a 
  33. starting address and a count of the number of units of memory that
  34. will be filled. The range is specified as <addr>,<addr> then this is converted
  35. to <addr>:<count>. This may mean the ending address is not the same as
  36. the typed ending address as the block fill will not partially fill a
  37. memory area of demension <size>, but rather abreviate the area filled.
  38. Third we get the <data> from the command line. If there is more data
  39. than <size> would permit, we will truncate later.
  40.  
  41. If we get this far, then there will be no more chance of errors
  42. from the command line. To tell the user what is going on, we
  43. print the starting address that we will fill and the the ending address.
  44. Then we fill in the data by one of three tight loops. If the default case
  45. is reached, then the getsize() routine made an error.
  46.  
  47. The data fill loop starts by truncating any unneeded data from the front
  48. of the data line. Next, a printout of the data used is made. Then, the
  49. assembly language routines are called that will put 8, 16 or 32 bits of data
  50. into the memory area. As the data is inserted, then the address is read and
  51. compared with the data. If the data written and the data read do not agree,
  52. then an error message is printed and the command returns to the main loop.
  53. If the data matches, the count is decremented and the starting address
  54. is incremented by either 1, 2 or 4 bytes. Finally, a check is made to see
  55. if the user has typed a cancel instruction. If so, then return with no further
  56. memory changed, though the memory already filled will remain changed.
  57. */
  58. /* **************************************************** */
  59.  
  60. bfcmd(argc,argv)
  61. int argc;    /* number of arguments in the command line */
  62. char *argv;    /* the command line in ASCII */
  63. {
  64.  
  65. extern int error;    /* global flag from getnum */
  66. register int size;    /* size of data to fill into memory*/
  67. register int start;    /* the starting address to begin fill at */
  68. register int count;    /* the number of 8, 16, or 32 bit increments to fill into memory */
  69. register int data;    /* the information to fill into the memory */
  70.  
  71.     if (argc == 3 || argc == 4)
  72.     {
  73.         striparg(argv);
  74.         size = getsize(argv,ERR04);
  75.         if (size < 0)
  76.             return(0);
  77.         start = getnum(argv,ERR02,DEFAULTSCALE);
  78.         if (error)
  79.             return(0);
  80.         count = getcount(argv,size,start);
  81.         if (count < 0)
  82.         {
  83.             print(ERR02);
  84.             return(0);
  85.         }
  86.         data = getnum(argv,ERR03,DEFAULTSCALE);
  87.         if (error)
  88.             return(0);
  89.         print("Starting address: %c%8x\n",HEXDEL,start);
  90.         print("Ending   address: %c%8x\n",HEXDEL,start + count * size - 1);
  91.         switch (size)
  92.         {
  93.             case 1:
  94.                 data = data & MASK8;
  95.                 print("Data     entered: %c%2x\n",HEXDEL,data);
  96.                 while (count > 0)
  97.                 {
  98.                     put8(start,data);
  99.                     if(data != get8(start))
  100.                     {
  101.                         print("Memory fault at %c%8x\nData written %c%2x\nData read %c%2x\n",HEXDEL,start,HEXDEL,data,HEXDEL,get8(start));
  102.                         return(0);
  103.                     }
  104.                     count--;
  105.                     start = start + 1;
  106.                     if(check())
  107.                         break;
  108.                 }
  109.                 break;
  110.             case 2:
  111.                 data = data & MASK16;
  112.                 print("Data     entered: %c%4x\n",HEXDEL,data);
  113.                 while (count > 0)
  114.                 {
  115.                     put16(start,data);
  116.                     if(data != get16(start))
  117.                     {
  118.                         print("Memory fault at %c%8x\nData written %c%4x\nData read %c%4x\n",HEXDEL,start,HEXDEL,data,HEXDEL,get16(start));
  119.                         return(0);
  120.                     }
  121.                     count--;
  122.                     start = start + 2;
  123.                     if(check())
  124.                         break;
  125.                 }
  126.                 break;
  127.             case 4:
  128.                 print("Data     entered: %c%8x\n",HEXDEL,data);
  129.                 while(count >0)
  130.                 {
  131.                     put32(start,data);
  132.                     if(data != get32(start))
  133.                     {
  134.                         print("Memory fault at %c%8x\nData written %c%8x\nData read %c%8x\n",HEXDEL,start,HEXDEL,data,HEXDEL,get32(start));
  135.                         return(0);
  136.                     }
  137.                     count--;
  138.                     start = start + 4;
  139.                     if(check())
  140.                         break;
  141.                 }
  142.                 break;
  143.             default :
  144.                 return(0);
  145.         }
  146.      }
  147.     else
  148.         print(ERR01);
  149.         
  150. }
  151.  
  152. /* ****************************************************** */
  153.